<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>选课列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../resources/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../resources/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>组件</cite></a>
      <a><cite>数据表格</cite></a>
      <a><cite>开启头部工具栏</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">选课信息列表</div>
          <div class="layui-card-body">
            <table class="layui-hide" id="studentCourse-list" lay-filter="studentCourse-list"></table>
             
            <script type="text/html" id="operation">
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="../../../resources/layuiadmin/layui/layui.js"></script>
  <script src="../../../resources/js/common.js"></script>
  <script>
  layui.config({
    base: '../../../resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var table = layui.table
    ,$ = layui.$
    ,layer = layui.layer;
  
    table.render({
      elem: '#studentCourse-list'
      ,id: 'studentCourseTable'
      ,url: '/admin/listStudentCourse'
      ,toolbar: '#operation'
      ,title: '选课信息列表'
      ,cols: [[
         {field:'studentCourseId', title:'选课ID号', width:120, fixed: 'left', unresize: true, sort: true},
         {title:'课程ID号', width:120, sort: true, templet: function(data){
             return data.course.courseId;
           }},
         {title:'课程名', width:120, sort: true, templet: function(data){
             return data.course.courseName;
           }},
        {title:'选课学生ID号', width:150, sort: true, templet: function(data){
            return data.student.studentId;
          }},
        {title:'学生姓名', width:120, sort: true, templet: function(data){
            return data.student.studentName;
          }},
         {title:'创建时间', width:120, templet: function(res){
             return new Date(res.createTime).Format("yyyy-MM-dd");
        }},
         {fixed: 'right', title:'操作', toolbar: '#operation', width:150}
      ]]
      ,page: true
    });
    
    //监听行工具事件
    table.on('tool(studentCourse-list)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('确定要删除吗', function(index){
          delStudentCourseById(data.studentCourseId);
          layer.close(index);
        });
      }
    });

    //删除记录
    function delStudentCourseById(id) {
      $.get("/admin/deleteStudentCourse?studentCourseId=" + id,
              function(res) {
                if(res.success){
                  layer.msg('删除成功');
                  table.reload('studentCourseTable', {//studentCourseTable是组件名称,表格名
                    page: {//page参数是指重新刷新后从第几页开始
                      curr: 1 //重新从第 1 页开始
                    }
                  }, 'data');//data是默认值
                }
              });
    }

  });
  </script>

</body>
</html>